package com.pengzy.auth.controller;

import com.alibaba.fastjson2.JSONObject;
import com.pengzy.auth.dto.LoginBo;
import com.pengzy.auth.services.LoginService;
import com.pengzy.comment.core.annotation.ApiLog;
import com.pengzy.comment.core.enums.OperateEnum;
import com.pengzy.comment.web.result.JsonResult;
import com.pengzy.supports.dto.LoginUser;
import com.pengzy.supports.dto.LoginUserDetails;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

/**
 * @author xiaozhi 2023/7/7
 */

@RestController
@RequestMapping("/core")
@Api(tags = "登录")
@Slf4j(topic = "api-log")
public class LoginController {


    @Resource
    private LoginService loginService;


    @RequestMapping(value = "/login",method = RequestMethod.POST)
    @ApiOperation(value = "登录")
    @ApiLog(method = "登录",type= OperateEnum.LOGIN)
    public JsonResult<LoginUser> login(@Validated @RequestBody LoginBo bo){
        return loginService.login(bo);
    }

    @RequestMapping(value = "/logOut",method = RequestMethod.POST)
    @ApiOperation(value = "登出")
    @ApiLog(method = "登出",type= OperateEnum.LOGIN)
    public JsonResult<String> logOut(@Validated @RequestBody LoginBo bo){
        return loginService.logout(bo);
    }

    @RequestMapping(value = "/test",method = RequestMethod.POST)
    @ApiOperation(value = "测试")
    @ApiLog(method = "测试",type= OperateEnum.QUEY)
    public JsonResult<String> test(@Validated @RequestBody LoginBo bo){
        return JsonResult.success("测试成功",JSONObject.toJSONString(bo));
    }

}
